<!--区域管理-->
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<title>医院维护</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="resources/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="resources/css/public.css" media="all" />
	<link rel="stylesheet" href="resources/layui_ext/dtree/dtree.css">
    <link rel="stylesheet" href="resources/layui_ext/dtree/font/dtreefont.css">
</head>
<body class="childrenBody">
<!--查询条件-->
<div class="layui-collapse" id="search">
    <blockquote class="layui-elem-quote quoteBox">
    <form class="layui-form" id="hospitalTable" lay-filter="hospitalTable">
	    <div class="layui-form-item layui-center">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">医院名称</label>
                	<div class="layui-input-block">
                	    <input type="hidden" name="id">
                	    <input type="text" name="hospitalName" class="layui-input searchVal"/>
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-center">
                <div class="layui-input-block">
                   <button type="submit" class="layui-btn" lay-submit="" lay-filter="sub">查询</button>
                </div>
            </div>
        </div>
	</form>
	</blockquote>
</div>
<!--数据表格-->
<div>
    <table class="layui-hide" id="hospitalShowTable" lay-filter="hospitalShowTable"></table>
    <div id="toolBars" style="display: none">
        <button type="button" lay-event="add" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-add-1"></span>添加</button>
    </div>
    <div id="rowBars" style="display: none">
        <button type="button" lay-event="show" class="layui-btn layui-btn-sm layui-btn-warm"><span class="layui-icon layui-icon-search"></span>查看</button>
        <button type="button" lay-event="update" class="layui-btn layui-btn-sm layui-bg-green"><span class="layui-icon layui-icon-edit"></span>修改</button>
        <button type="button" lay-event="delete" class="layui-btn layui-btn-sm layui-btn-danger"><span class="layui-icon layui-icon-delete"></span>删除</button>
    </div>
</div>
<!--添加修改弹出层-->
<div id="addOrUpdate" style="display: none">
    <form class="layui-form" id="addOrUpdateTable" lay-filter="addOrUpdateTable">
	    <div class="layui-form-item layui-row">
	        <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">医院名称</label>
                	<div class="layui-input-block">
                		<input type="text" name="hospitalName" lay-verify="required" class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">通讯地址</label>
                	<div class="layui-input-block">
                		<input type="text" name="communication" lay-verify="required" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">邮政编码</label>
                	<div class="layui-input-block">
                		<input type="text" lay-verify="required|number" name="postal" class="layui-input searchVal"/>
                	</div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">所属地区</label>
                	<div class="layui-input-block">
                	    <input name="areaid" id="areaid" type="hidden">
                		<ul id="areaidtree" class="dtree" data-id="0"></ul>
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">医院级别</label>
                	<div class="layui-input-block">
                	    <input type="hidden" name="id">
                	    <select name="level" readonly lay-filter="level">
                            <option value="1">卫生室</option>
                        </select>
                	</div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">床位数</label>
                	<div class="layui-input-block">
                		<input type="text" name="bednum" lay-verify="number" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">是否非营利性医疗机构</label>
                	<div class="layui-input-block">
                	    <input type="hidden" name="id">
                		<input type="radio" name="isProfit" value="0" title="否" checked="">
                        <input type="radio" name="isProfit" value="1" title="是">
                	</div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">院办电话</label>
                	<div class="layui-input-block">
                		<input type="text" name="hospitalPhone" lay-verify="required|phone" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">院办传真</label>
                	<div class="layui-input-block">
                		<input type="text" name="hospitalFax" class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">药剂科电话</label>
                	<div class="layui-input-block">
                		<input type="text" name="drugPhone" lay-verify="required|phone" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">上年度药品收入</label>
                	<div class="layui-input-block">
                		<input type="text" name="drugProfit" lay-verify="number" class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">上年度业务收入(万元)</label>
                	<div class="layui-input-block">
                		<input type="text" name="busProfit" lay-verify="number" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">医院类型</label>
                	<div class="layui-input-block">
                		<select name="type"  lay-filter="type">
                            <option value="1">综合性医院</option>
                            <option value="2">专科医院</option>
                        </select>
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-center">
                <div class="layui-input-block">
                   <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">提交</button>
                </div>
            </div>
        </div>
  	</form>
</div>
<!--查看弹出层-->
<div id="show" style="display: none">
    <form class="layui-form" id="showTable" lay-filter="showTable">
	    <div class="layui-form-item layui-row">
	        <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">医院名称</label>
                	<div class="layui-input-block">
                		<input type="text" name="hospitalName" readonly lay-verify="required" class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">通讯地址</label>
                	<div class="layui-input-block">
                		<input type="text" name="communication" readonly lay-verify="required" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">邮政编码</label>
                	<div class="layui-input-block">
                		<input type="text" lay-verify="required" readonly name="postal" class="layui-input searchVal"/>
                	</div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">所属地区</label>
                	<div class="layui-input-block">
                	    <input type="hidden" name="areaid">
                	    <ul id="areaidtree2" class="dtree" data-id="0"></ul>
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">医院级别</label>
                	<div class="layui-input-block">
                	    <input type="hidden" name="id">
                	    <select name="level" readonly lay-filter="level">
                            <option value="1">卫生室</option>
                        </select>
                	</div>
                	<div class="mydiv" title="不可修改" style="position:absolute;width: 100%;height: 100%;left: 0px;top: 0px;background: #fff;opacity: 0;filter:alpha(opacity=0)"></div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">床位数</label>
                	<div class="layui-input-block">
                		<input type="text" name="bednum" readonly lay-verify="number" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">是否非营利性医疗机构</label>
                	<div class="layui-input-block">
                	    <input type="hidden" name="id">
                		<input type="radio" name="isProfit" value="0" title="否" checked="">
                        <input type="radio" name="isProfit" value="1" title="是">
                	</div>
                	<div class="mydiv" title="不可修改" style="position:absolute;width: 100%;height: 100%;left: 0px;top: 0px;background: #fff;opacity: 0;filter:alpha(opacity=0)"></div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">院办电话</label>
                	<div class="layui-input-block">
                		<input type="text" readonly name="hospitalPhone" lay-verify="required|phone" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">院办传真</label>
                	<div class="layui-input-block">
                		<input type="text" readonly name="hospitalFax" class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">药剂科电话</label>
                	<div class="layui-input-block">
                		<input type="text" readonly name="drugPhone" lay-verify="required|phone" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">上年度药品收入</label>
                	<div class="layui-input-block">
                		<input type="text" readonly name="drugProfit" class="layui-input searchVal"  />
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">上年度业务收入(万元)</label>
                	<div class="layui-input-block">
                		<input type="text" readonly name="busProfit" lay-verify="number" class="layui-input searchVal"  />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">医院类型</label>
                	<div class="layui-input-block">
                		<select name="type" readonly lay-filter="type">
                            <option value="1">综合性医院</option>
                            <option value="2">专科医院</option>
                        </select>
                        <div class="mydiv" title="不可修改" style="position:absolute;width: 100%;height: 100%;left: 0px;top: 0px;background: #fff;opacity: 0;filter:alpha(opacity=0)"></div>
                	</div>
                </div>
            </div>

        </div>
  	</form>
</div>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script type="text/javascript" src="/resources/layui_ext/dtree/dtree.js"></script>
<script>
    layui.extend({
              dtree: '/resources/layui_ext/dtree/dtree'   // {/}的意思即代表采用自有路径，即不跟随 base 路径
            }).use(['form','laydate','element','layer','jquery','table'],function(){
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        var table = layui.table;
        var dtree = layui.dtree;
        var laydate = layui.laydate;
        laydate.render({
            elem:'#licenceDeadline'
            ,type: 'datetime'
        })
        var tableIns = table.render({
            elem:"#hospitalShowTable",
            url:"/hospital/loadHospital",
            toolbar:"#toolBars",
            page:true,
            height:'full',
            cols:[
                [
                    {type:'checkbox',fixed:'center'}
                    ,{field:'id', title:'ID',  fixed: 'left', unresize: true,width:'80' ,sort: true,align:'center'}
                    ,{field:'hospitalName', title:'医院名称',align:'center',width:'180'}
                    ,{field:'communication', title:'通讯地址',align:'center',width:'150'}
                    ,{field:'postal', title:'邮政编码',align:'center',width:'150'}
                    ,{field:'areaid', title:'所属地区',align:'center',width:'150',templet:function(res) {
                        var result;
                        if(res.areaid!=null&&res.areaid!=undefined){
                            $.ajax({
                                url:"area/getPidName?id="+res.areaid,
                                async:false,
                                type:"get",
                                success:function(r) {
                                    result = r;
                                }
                            });
                        }
                        return result==undefined?"":result;
                    }}
                    ,{field:'level', title:'医院级别',align:'center',width:'150',templet:function(res) {
                        return res.level==1?"卫生室":"";
                    }}
                    ,{field:'bednum', title:'床位数',align:'center',width:'150'}
                    ,{field:'isProfit', title:'是否非营利性医疗机构',align:'center',width:'150',templet:function(res) {
                        return res.isProfit==0?"否":"是";
                    }}
                    ,{field:'hospitalPhone', title:'院办电话',align:'center',width:'180'}
                    ,{field:'hospitalFax', title:'院办传真',align:'center',width:'150'}
                    ,{field:'drugPhone', title:'药剂科电话',align:'center',width:'150'}
                    ,{field:'type', title:'医院类型',align:'center',width:'150',templet:function(res) {
                        return res.type==1?"综合性医院":"专科医院";
                    }}
                    ,{field:'drugProfit', title:'上年度药品收入',align:'center',width:'150'}
                    ,{field:'busProfit', title:'上年度业务收入',align:'center',width:'150'}
                    ,{fixed: 'right', title:'操作', toolbar: '#rowBars',width:260}
                ]
            ]
        });
        //加载下拉树
        var areaidtree = dtree.renderSelect({
            elem: "#areaidtree",
            width: "100%", // 指定树的宽度
            url: "/area/loadTree",
            checkbar: true,
            checkbarType: "all", // 默认就是all，其他的值为： no-all  p-casc   self  only
            dataStyle: "layuiStyle",  //使用layui风格的数据格式
            dataFormat: "list",  //配置data的风格为list
            response:{message:"msg",statusCode:0}  //修改response中返回数据的定义
        });
        var areaidtree2 = dtree.renderSelect({
            elem: "#areaidtree2",
            width: "100%", // 指定树的宽度
            url: "/area/loadTree",
            checkbar: true,
            checkbarType: "all", // 默认就是all，其他的值为： no-all  p-casc   self  only
            dataStyle: "layuiStyle",  //使用layui风格的数据格式
            dataFormat: "list",  //配置data的风格为list
            response:{message:"msg",statusCode:0}  //修改response中返回数据的定义
        });
        //监听下拉树的单击方法
        dtree.on("node('areaidtree')" ,function(obj){
            $("#areaid").val(obj.param.nodeId);
            console.log(obj);
        });
        //模糊表单提交
        form.on("submit(sub)",function(data) {
            tableIns.reload({
                where:data.field
            })
            return false;
        })

        var mainIns;
        var url;
        //监听头部工具栏事件
        table.on('toolbar(hospitalShowTable)',function(obj) {
            switch (obj.event) {
                case 'add':
                    openAdd();
            }
        });
        //监听行工具栏事件
        table.on('tool(hospitalShowTable)',function(obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'show':
                    openShow(data);
                    break;
                case 'update':
                    openUpdate(data);
                    break;
                case 'delete':
                    openDelete(data);
            }
        });
        //提交表单
        form.on('submit(submit)',function() {
            var params = $("#addOrUpdateTable").serialize();
            $.post(url,params,function(data) {
                //提示信息
                layer.msg(data.msg);
                //关闭弹出层
                layer.close(mainIns);
                //重新渲染table
                tableIns.reload();
            })
            return false;
        });
        //关闭弹出层
        form.on('submit(close)',function() {
            var params = $("#addOrUpdateTable").serialize();
            $.post(url,params,function(data) {
                //关闭弹出层
                layer.close(mainIns);
            })
            return false;
        });
        //打开添加弹出层
        function openAdd() {
            mainIns = layer.open({
                type:1,
                content:$("#addOrUpdate"),
                area:['900px','480px'],
                title:"添加用户",
                success:function(layero,index) {
                    //更改url
                    url = "/hospital/add";
                    $("#addOrUpdateTable")[0].reset();

                }
            })
        }
        //打开修改弹出层
        function openUpdate(data) {
            url = "/hospital/update";
            mainIns = layer.open({
                type:1,
                content:$("#addOrUpdate"),
                area:['800px','480px'],
                title:"修改用户",
                success:function(index) {
                    form.val("addOrUpdateTable",data);
                    $("#typeShow").val(data.type);
                    //刷新下拉树
                    dtree.dataInit("areaidtree",data.areaid);
                    dtree.setSelectValue("areaidtree");
                }
            })
        }

        //打开查看弹出层
        function openShow(data) {
            mainIns = layer.open({
                type:1,
                content:$("#show"),
                area:['800px','480px'],
                title:"查看用户",
                success:function(index) {
                    console.log(data);
                    form.val("showTable",data);
                    $("#typeShow").val(data.type==1?"局":"院");
                    dtree.dataInit("areaidtree2",data.areaid);
                    dtree.setSelectValue("areaidtree2");
                }
            })
        }
        //打开删除弹出层
        function openDelete(data) {
            mainIns = layer.confirm('您真的要删除吗？', {
                btn: ['删除','取消'] //按钮
            }, function(){
                $.post("/hospital/delete",{id:data.id},function(res) {
                    layer.msg(res.msg);
                    tableIns.reload();
                })
            })
        }
    })
</script>
</body>
</html>